/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package controller.action;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import model.database.SqlBook;
import model.database.SqlComment;
import model.entities.Account;
import model.entities.Book;

/**
 *
 * @author THANH
 */
public class CommentAction implements Action{

    public void exe(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
        HttpSession session = request.getSession();
        Account acc = (Account)session.getAttribute("Account");
        int bId = Integer.parseInt(request.getParameter("Id"));
        String title = request.getParameter("txtTitle");
        String content = request.getParameter("txtContent");
        SqlComment sqlComment = new SqlComment();
        int i = sqlComment.createComment(bId, acc.getUsername(), title, content); 
        Book book = (Book)session.getAttribute("Book"); 
        book.setListComm(sqlComment.getListComment(bId));
        session.setAttribute("Book", book);
        request.getRequestDispatcher("Controller?Action=BookAction&Id="+bId).forward(request, response);
    }
    
}
